package com.ciwong.epaper.widget.evaluate;


import android.content.Context;

import android.os.Handler;
import android.util.AttributeSet;

import android.widget.FrameLayout;


import com.ciwong.epaper.modules.evaluate.ui.WordBottomView;

import com.ciwong.mobilelib.widget.CWPopMenu;


/**
 * BaseFrameLayout
 *
 * @author sugy
 * @version ciwong v.1.0 2015/12/18 18:34
 * @since ciwong v.1.0
 */
public class BaseFrameLayout extends FrameLayout {

    Handler mHandler = new Handler();


    private WordBottomView wordBottomView;


    private CWPopMenu popMenu;

    private long userId;

    public BaseFrameLayout(Context context) {
        super(context);
    }

    public BaseFrameLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public BaseFrameLayout(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void initData(WordBottomView wordBottomView, long userId) {
        this.wordBottomView = wordBottomView;
        this.userId = userId;
    }

    /**
     * 重置到初始状态
     */
    public void resetInitState(boolean mIsUnAutoMode) {
        resetInitState(true, mIsUnAutoMode);
    }

    public void resetInitState(final boolean isShow, final boolean mIsUnAutoMode) {//初始状态
        if (wordBottomView == null) {
            return;
        }

        mHandler.post(new Runnable() {
            @Override
            public void run() {//初始状态
                wordBottomView.setInitState(mIsUnAutoMode);
            }
        });
    }

    /*
     *停止手动播放状态
     */
    public void playstopState(final boolean isPlay) {
        if (wordBottomView == null) {
            return;
        }
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                wordBottomView.setPlayWordState(isPlay);
            }
        });

    }

    /*
     *播放提示音时图标状态
     */
    public void playHintState(final boolean mIsUnAutoMode) {
        if (wordBottomView == null) {
            return;
        }
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                wordBottomView.playHintState(mIsUnAutoMode);
            }
        });

    }

    /**
     * 开始录音语句
     * 录音状态
     */
    public void startRecord(final boolean mIsUnAutoMode) {
        if (wordBottomView == null) {
            return;
        }
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                wordBottomView.recordingState(mIsUnAutoMode);
            }
        });
    }

    /**
     * 自动更新进度
     */
    public void autoUpdateProgress(final int timer) {
        if (wordBottomView == null) {
            return;
        }
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                wordBottomView.autoUpdateProgress(timer);
            }
        });
    }


    /**
     * 开始播放单词状态
     */
    public void play(final boolean mIsUnAutoMode) {
        if (wordBottomView == null) {
            return;
        }
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                wordBottomView.payWordsState(mIsUnAutoMode);
            }
        });
    }


}
